package com.wwu.system.controller;

import com.wwu.common.constant.CommConst;
import com.wwu.common.enums.MenuBtnEnum;
import com.wwu.common.web.ResultObj;
import com.wwu.common.web.ResultPage;
import com.wwu.system.common.aspect.Log;
import com.wwu.system.entity.SysQuartzLog;
import com.wwu.system.service.ISysQuartzLogService;
import com.wwu.system.vo.QueryVO;
import io.swagger.annotations.*;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.Arrays;

/**
 * 定时任务日志前端控制器
 * @author 一蓑烟雨
 * @date 2023/5/31 9:37
 */
@Api(tags = "定时任务日志控制器(SysQuartzLogController)")
@ApiSort(3)
@Controller
@RequestMapping("/system/sysQuartzLog")
public class SysQuartzLogController {
    @Resource
    private ISysQuartzLogService sysQuartzLogService;

    /**
     * 请求转发到定时任务日志主页面
     * @return java.lang.String
     * @author 一蓑烟雨
     * @date 2023/7/11 14:54
     */
    @GetMapping("/quartzLogMain")
    public String quartzLogMain(String quartzId,Model model){
        model.addAttribute("quartzId",quartzId);
        return "system/sysquartz/quartz-log-main";
    }

    @Log(menuName = "定时任务日志",menuBtnEnum = MenuBtnEnum.SHOW)
    @ApiOperation(value = "查询定时任务日志")
    @ApiOperationSupport(order = 1)
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "当前页数",paramType = "query", required = true),
            @ApiImplicitParam(name = "limit", value = "每页条数",paramType = "query", required = true),
            @ApiImplicitParam(name = "sysQuartzLog", value = "定时任务日志实体"),
            @ApiImplicitParam(name = "queryVO", value = "前端查询条件封装实体类"),
    })
    @GetMapping("/quartzLogList")
    @ResponseBody
    public ResultPage<SysQuartzLog> getQuartLogListPage(@RequestParam(defaultValue = "1") Integer page,
                                                        @RequestParam(defaultValue = "5000") Integer limit,
                                                        SysQuartzLog sysQuartzLog, QueryVO queryVO){
        return sysQuartzLogService.getQuartLogListPage(page,limit,sysQuartzLog,queryVO);
    }

    @Log(menuName = "定时任务日志",menuBtnEnum = MenuBtnEnum.DEL)
    @ApiOperation(value = "删除定时任务日志")
    @ApiOperationSupport(order = 2)
    @DeleteMapping("/deleteBatchQuartzLog/{quartzIds}")
    @ResponseBody
    public ResultObj deleteBatchQuartzLog(@ApiParam(name = "quartzIds", value = "定时任务id集合，以逗号分隔", required = true)
                                @PathVariable String quartzIds){
        sysQuartzLogService.deleteQuartzLogByIds(Arrays.asList(quartzIds.split(CommConst.SPLIT_COMMA)));
        return ResultObj.success("定时任务日志删除成功");
    }
}